<?php
/**
 * Created by PhpStorm.
 * User: evenvi
 * Date: 16-8-11
 * Time: 上午10:43
 */

function ping(swoole_process $process)
{
    while (1)
    {
        sleep(3);

        $buffer = "";
        $buffer .= chr(0xc0);
        $buffer .= chr(0x00);


//        send($buffer);
        $sockid = \swoole_table()->get('sock_id');
        echo "ChildProcess sock_id : ".$sockid . "\n";
        var_dump($process);
        echo $process->pid,"\t",$process->callback .PHP_EOL;
        echo "Sending Ping \n";
    }

}

function send($data)
{
    $client = new \swoole_client(SWOOLE_SOCK_TCP);
    if (!$client->connect('127.0.0.1', 1883, -1))
    {
        exit("connect failed. Error: {$client->errCode}\n");
    }
    $client->send($data);
    $client->close();
}